#region Usings

using System;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Linq.Expressions;
using RailNet.Dao.Entity;

#endregion

namespace RailNet.Dao.Repository
{
    public class PriceSerialRepository : IPriceSerialRepository
    {
        private readonly RailnetContext _context = new RailnetContext();

        #region IPriceSerialRepository Members

        public IQueryable<PriceSerial> All
        {
            get { return _context.PriceSerials; }
        }

        public IQueryable<PriceSerial> AllIncluding(params Expression<Func<PriceSerial, object>>[] includeProperties)
        {
            IQueryable<PriceSerial> query = _context.PriceSerials;
            foreach (var includeProperty in includeProperties)
            {
                query = query.Include(includeProperty);
            }
            return query;
        }

        public PriceSerial Find(long id)
        {
            return _context.PriceSerials.Find(id);
        }

        public void InsertOrUpdate(PriceSerial priceserial)
        {
            if (priceserial.Id == default(long))
            {
                // New entity
                _context.PriceSerials.Add(priceserial);
            }
            else
            {
                // Existing entity
                _context.Entry(priceserial).State = EntityState.Modified;
            }
        }

        public void Delete(long id)
        {
            var priceserial = _context.PriceSerials.Find(id);
            _context.PriceSerials.Remove(priceserial);
        }

        public void Save()
        {
            _context.SaveChanges();
        }

        #endregion
    }
}